package ir.values.users.constants;

import frontend.visitor.symboltbl.scope.Scope;
import ir.types.Type;
import ir.types.datatypes.ArrayType;
import ir.types.datatypes.DataType;
import ir.types.datatypes.VoidType;

import java.util.ArrayList;

public class ArrayConst extends Constant {
    private final ArrayList<Constant> childConstants;
    public ArrayConst(ArrayList<Constant> childConstants) {
        super(new ArrayType(
                childConstants.isEmpty() ? VoidType.VOID : childConstants.get(0).getDataType(),
                childConstants.size()));
        this.childConstants = childConstants;
    }
    @Override
    public String parseLLVM() {
        StringBuilder sb = new StringBuilder();
        sb
                .append(type)
                .append(" [");
        for (int i = 0; i < childConstants.size(); i++) {
            Constant childConstant = childConstants.get(i);
            sb.append(childConstant.parseLLVM());
            if (i != childConstants.size() - 1) {
                sb.append(", ");
            }
        }
        sb
                .append("]");
        return sb.toString();
    }
}
